package com.atguigu.rabbitmq.utils;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * ClassName: RabbitMQUtils
 * Description: 此类为连接工厂创建信道的工具类
 * Date: 2023/04/27 PM 2:58:32
 * <p>
 * project: atguigu-rabbitmq
 * package: com.atguigu.rabbitmq.utils
 * email: 1085844536@qq.com
 * version:
 *
 * @author WangGuojian
 */
public final class RabbitMqUtils {

    /**
     * 得到一个channel
     */
    public static Channel getChannel() throws Exception {
        // 创建连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        // 工厂IP连接RabbitMQ队列
        factory.setHost("192.168.0.20");
        // 用户名
        factory.setUsername("admin");
        // 密码
        factory.setPassword("admin");

        // 创建连接
        Connection connection = factory.newConnection();
        // 创建信道
        return connection.createChannel();
    }

    private RabbitMqUtils() {
    }
}
